﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 学生选课及成绩查询管理系统
{
    public partial class addClassInfo : Form
    {
        public addClassInfo()
        {
            InitializeComponent();
        }

        private void btn_sub_Click(object sender, EventArgs e)
        {
            string clano = txt_clano.Text;
            string claname = txt_claname.Text;
            if (string.IsNullOrEmpty(clano) || string.IsNullOrEmpty(claname) )
            {
                MessageBox.Show("请输入完整信息");
                return;
            }
            if (clano.Count()>20)
            {
                
            }
            string sql = "insert into class(classno,classname) values(@clano,@claname)";
            SqlParameter[] sqlarray = { new SqlParameter("@clano", clano), new SqlParameter("@claname", claname), };

            int res = DBAccess.GetState(sql, sqlarray);
            if (res != 0)
            {
                MessageBox.Show("成功添加班级信息");
                addClassInfo_Load(sender,e);
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void addClassInfo_Load(object sender, EventArgs e)
        {
            string sql = "select * from class";
            DataTable dt=DBAccess.GetTable(sql);
            dataGridView1.DataSource = dt;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = dataGridView1.CurrentCellAddress.Y + 1;
            int col = dataGridView1.CurrentCellAddress.X + 1;
            txt_clano.Text = dataGridView1.Rows[row - 1].Cells[0].Value.ToString();
            txt_claname.Text = dataGridView1.Rows[row - 1].Cells[1].Value.ToString();
        }
    }
}
